package com.ks.user.service.impl;

import com.ks.core.constant.Const;
import com.ks.core.exception.GunsException;
import com.ks.core.util.ToolUtil;
import com.ks.user.entity.BaseSysConfig;
import com.ks.user.dao.BaseSysConfigMapper;
import com.ks.user.service.IBaseSysConfigService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 基础表-系统参数配置-系统全局开关配置 服务实现类
 * </p>
 *
 * @author kingdee123
 * @since 2020-12-23
 */
@Service
public class BaseSysConfigServiceImpl extends ServiceImpl<BaseSysConfigMapper, BaseSysConfig> implements IBaseSysConfigService {

    @Resource
    private BaseSysConfigMapper baseSysConfigMapper;

    @Override
    public String getComponentAppId() {
        BaseSysConfig baseSysConfig = baseSysConfigMapper.selectById(Const.Wx.COMPONENT_APP_ID);
        if (ToolUtil.isNotEmpty(baseSysConfig)) {
            return baseSysConfig.getConfigValue();
        } else {
            throw new GunsException("第三方平台ID为空！！！");
        }
    }

    @Override
    public String getComponentAppSecret() {
        BaseSysConfig baseSysConfig = baseSysConfigMapper.selectById(Const.Wx.COMPONENT_SECRET);
        if (ToolUtil.isNotEmpty(baseSysConfig)) {
            return baseSysConfig.getConfigValue();
        } else {
            throw new GunsException("第三方平台秘钥为空！！！");
        }
    }

    @Override
    public String getComponentAccessToken() {
        BaseSysConfig baseSysConfig = baseSysConfigMapper.selectById(Const.Wx.COMPONENT_TOKEN);
        if (ToolUtil.isNotEmpty(baseSysConfig)) {
            return baseSysConfig.getConfigValue();
        } else {
            throw new GunsException("第三方平台令牌为空！！！");
        }
    }

    @Override
    public String getComponentTicket() {
        BaseSysConfig baseSysConfig = baseSysConfigMapper.selectById(Const.Wx.COMPONENT_TICKET);
        if (ToolUtil.isNotEmpty(baseSysConfig)) {
            return baseSysConfig.getConfigValue();
        } else {
            throw new GunsException("第三方平台TicKet为空或过期！！！");
        }
    }

    @Override
    public String getSystemRootUrl() {
        BaseSysConfig baseSysConfig = baseSysConfigMapper.selectById(Const.Wx.TENANT_SYSTEM_ROOT_URL);
        if (ToolUtil.isNotEmpty(baseSysConfig)) {
            return baseSysConfig.getConfigValue();
        } else {
            throw new GunsException("第三方平台TicKet为空或过期！！！");
        }
    }
}
